﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.LIB.YJKControls;
using YJKArch.ImportStructureProject.ImportObjects;

namespace YJKArch.ImportStructureProject
{
	public partial class SectionPropertyMappingForm : System.Windows.Forms.Form
	{
		public List<RectSectionMapping> RBeamMapping
		{
			get
			{
				return this.m_RBeamMapping;
			}
		}

		public List<RectSectionMapping> RColumnMapping
		{
			get
			{
				return this.m_RColumnMapping;
			}
		}

		public List<CircleSectionMapping> CColumnMapping
		{
			get
			{
				return this.m_CColumnMapping;
			}
		}

		public SectionPropertyMappingForm(List<RectSectionMapping> rBeamMapping, List<RectSectionMapping> rColumnMapping, List<CircleSectionMapping> cColumnMapping)
		{
			this.m_RBeamMapping = rBeamMapping;
			this.m_RColumnMapping = rColumnMapping;
			this.m_CColumnMapping = cColumnMapping;
			this.InitializeComponent();
			this.InitializeComponentDate();
		}

		private void InitializeComponentDate()
		{
			bool flag = false;
			if (this.m_RBeamMapping.Count > 0)
			{
				foreach (RectSectionMapping rectSectionMapping in this.m_RBeamMapping)
				{
					this.lbRBFamily.Items.Add(rectSectionMapping.FamilyName);
				}
				this.lbRBFamily.SelectedIndex = 0;
				this.SetCurrentRectBeamProperties(0);
				this.lbRBFamily.DrawMode = DrawMode.OwnerDrawVariable;
				if (!flag)
				{
					this.tabCtrlStyle.SelectedTab = this.tabPageRectangleBeam;
					flag = true;
				}
			}
			else
			{
				this.tabCtrlStyle.TabPages.Remove(this.tabPageRectangleBeam);
			}
			if (this.m_RColumnMapping.Count > 0)
			{
				foreach (RectSectionMapping rectSectionMapping2 in this.m_RColumnMapping)
				{
					this.lbRCFamily.Items.Add(rectSectionMapping2.FamilyName);
				}
				this.lbRCFamily.SelectedIndex = 0;
				this.SetCurrentRectColumnProperties(0);
				this.lbRCFamily.DrawMode = DrawMode.OwnerDrawVariable;
				if (!flag)
				{
					this.tabCtrlStyle.SelectedTab = this.tabPageRectangleColumn;
					flag = true;
				}
			}
			else
			{
				this.tabCtrlStyle.TabPages.Remove(this.tabPageRectangleColumn);
			}
			if (this.m_CColumnMapping.Count > 0)
			{
				foreach (CircleSectionMapping circleSectionMapping in this.m_CColumnMapping)
				{
					this.lbCCFamily.Items.Add(circleSectionMapping.FamilyName);
				}
				this.lbCCFamily.SelectedIndex = 0;
				this.SetCurrentCircleColumnProperties(0);
				this.lbCCFamily.DrawMode = DrawMode.OwnerDrawVariable;
				if (!flag)
				{
					this.tabCtrlStyle.SelectedTab = this.tabPageCircleColumn;
					flag = true;
					return;
				}
			}
			else
			{
				this.tabCtrlStyle.TabPages.Remove(this.tabPageCircleColumn);
			}
		}

		private void btnSetDiameter_Click(object sender, EventArgs e)
		{
			if (this.lbCCFamily.SelectedItem == null)
			{
				MessageBox.Show("没有选择族", "盈建科提示");
				return;
			}
			if (this.lbCCProperty.SelectedItem == null)
			{
				MessageBox.Show("没有选择尺寸属性", "盈建科提示");
				return;
			}
			int selectedIndex = this.lbCCFamily.SelectedIndex;
			int selectedIndex2 = this.lbCCProperty.SelectedIndex;
			this.m_CColumnMapping[selectedIndex].DiameterNameIndex = selectedIndex2;
			this.tbCCDiameter.Text = this.m_CColumnMapping[selectedIndex].SizeProperties[selectedIndex2];
		}

		private void btnSetWidth_Click(object sender, EventArgs e)
		{
			if (this.lbRCFamily.SelectedItem == null)
			{
				MessageBox.Show("没有选择族", "盈建科提示");
				return;
			}
			if (this.lbRCProperty.SelectedItem == null)
			{
				MessageBox.Show("没有选择尺寸属性", "盈建科提示");
				return;
			}
			int selectedIndex = this.lbRCFamily.SelectedIndex;
			int selectedIndex2 = this.lbRCProperty.SelectedIndex;
			if (this.m_RColumnMapping[selectedIndex].HeightNameIndex == selectedIndex2)
			{
				MessageBox.Show("宽/高数据不能相同", "盈建科提示");
				return;
			}
			this.m_RColumnMapping[selectedIndex].WidthNameIndex = selectedIndex2;
			this.tbRCWidth.Text = this.m_RColumnMapping[selectedIndex].SizeProperties[selectedIndex2];
			this.Refresh();
		}

		private void btSetHeight_Click(object sender, EventArgs e)
		{
			if (this.lbRCFamily.SelectedItem == null)
			{
				MessageBox.Show("没有选择族", "盈建科提示");
				return;
			}
			if (this.lbRCProperty.SelectedItem == null)
			{
				MessageBox.Show("没有选择尺寸属性", "盈建科提示");
				return;
			}
			int selectedIndex = this.lbRCFamily.SelectedIndex;
			int selectedIndex2 = this.lbRCProperty.SelectedIndex;
			if (this.m_RColumnMapping[selectedIndex].WidthNameIndex == selectedIndex2)
			{
				MessageBox.Show("宽/高数据不能相同", "盈建科提示");
				return;
			}
			this.m_RColumnMapping[selectedIndex].HeightNameIndex = selectedIndex2;
			this.tbRCHeight.Text = this.m_RColumnMapping[selectedIndex].SizeProperties[selectedIndex2];
			this.Refresh();
		}

		private void SizePropertyMappingForm_FormClosing(object sender, FormClosingEventArgs e)
		{
			if (base.DialogResult == DialogResult.OK)
			{
				string text = "";
				if (!this.IsFull(ref text))
				{
					MessageBox.Show(text, "盈建科提示");
					e.Cancel = true;
				}
			}
		}

		private bool IsFull(ref string message)
		{
			foreach (RectSectionMapping rectSectionMapping in this.m_RBeamMapping)
			{
				if (rectSectionMapping.HeightNameIndex == -1 || rectSectionMapping.WidthNameIndex == -1)
				{
					message = "矩形梁(" + rectSectionMapping.FamilyName + ")截面尺寸映射设置不完整！";
					return false;
				}
			}
			foreach (RectSectionMapping rectSectionMapping2 in this.m_RColumnMapping)
			{
				if (rectSectionMapping2.HeightNameIndex == -1 || rectSectionMapping2.WidthNameIndex == -1)
				{
					message = "矩形柱(" + rectSectionMapping2.FamilyName + ")截面尺寸映射设置不完整！";
					return false;
				}
			}
			foreach (CircleSectionMapping circleSectionMapping in this.m_CColumnMapping)
			{
				if (circleSectionMapping.DiameterNameIndex == -1)
				{
					message = "圆形柱(" + circleSectionMapping.FamilyName + ")截面尺寸映射设置不完整！";
					return false;
				}
			}
			return true;
		}

		private void lbRCFamily_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (this.lbRCFamily.SelectedItem == null)
			{
				return;
			}
			int selectedIndex = this.lbRCFamily.SelectedIndex;
			this.SetCurrentRectColumnProperties(selectedIndex);
		}

		private void SetCurrentRectBeamProperties(int familyIndex)
		{
			RectSectionMapping rectSectionMapping = this.m_RBeamMapping[familyIndex];
			this.lbRBProperty.Items.Clear();
			List<string> sizeProperties = rectSectionMapping.SizeProperties;
			foreach (string item in sizeProperties)
			{
				this.lbRBProperty.Items.Add(item);
			}
			if (rectSectionMapping.HeightNameIndex != -1)
			{
				this.tbRBHeight.Text = sizeProperties[rectSectionMapping.HeightNameIndex];
			}
			else
			{
				this.tbRBHeight.Text = "";
			}
			if (rectSectionMapping.WidthNameIndex != -1)
			{
				this.tbRBWidth.Text = sizeProperties[rectSectionMapping.WidthNameIndex];
				return;
			}
			this.tbRBWidth.Text = "";
		}

		private void SetCurrentRectColumnProperties(int familyIndex)
		{
			RectSectionMapping rectSectionMapping = this.m_RColumnMapping[familyIndex];
			this.lbRCProperty.Items.Clear();
			List<string> sizeProperties = rectSectionMapping.SizeProperties;
			foreach (string item in sizeProperties)
			{
				this.lbRCProperty.Items.Add(item);
			}
			if (rectSectionMapping.HeightNameIndex != -1)
			{
				this.tbRCHeight.Text = sizeProperties[rectSectionMapping.HeightNameIndex];
			}
			else
			{
				this.tbRCHeight.Text = "";
			}
			if (rectSectionMapping.WidthNameIndex != -1)
			{
				this.tbRCWidth.Text = sizeProperties[rectSectionMapping.WidthNameIndex];
				return;
			}
			this.tbRCWidth.Text = "";
		}

		private void lbCFamily_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (this.lbCCFamily.SelectedItem == null)
			{
				return;
			}
			int selectedIndex = this.lbCCFamily.SelectedIndex;
			this.SetCurrentCircleColumnProperties(selectedIndex);
		}

		private void SetCurrentCircleColumnProperties(int familyIndex)
		{
			CircleSectionMapping circleSectionMapping = this.m_CColumnMapping[familyIndex];
			this.lbCCProperty.Items.Clear();
			List<string> sizeProperties = circleSectionMapping.SizeProperties;
			foreach (string item in sizeProperties)
			{
				this.lbCCProperty.Items.Add(item);
			}
			if (circleSectionMapping.DiameterNameIndex != -1)
			{
				this.tbCCDiameter.Text = sizeProperties[circleSectionMapping.DiameterNameIndex];
				return;
			}
			this.tbCCDiameter.Text = "";
		}

		private void lbRCFamily_DrawItem(object sender, DrawItemEventArgs e)
		{
			System.Drawing.Color color = e.BackColor;
			if (!this.m_RColumnMapping[e.Index].IsSet)
			{
				color = System.Drawing.Color.Red;
			}
			e.Graphics.FillRectangle(new SolidBrush(color), e.Bounds);
			e.Graphics.DrawString(((ListBox)sender).Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), e.Bounds);
			e.DrawFocusRectangle();
		}

		private void lbCFamily_DrawItem(object sender, DrawItemEventArgs e)
		{
			System.Drawing.Color color = e.BackColor;
			if (!this.m_CColumnMapping[e.Index].IsSet)
			{
				color = System.Drawing.Color.Red;
			}
			e.Graphics.FillRectangle(new SolidBrush(color), e.Bounds);
			e.Graphics.DrawString(((ListBox)sender).Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), e.Bounds);
			e.DrawFocusRectangle();
		}

		private void btnSwap_Click(object sender, EventArgs e)
		{
			if (this.lbRCFamily.SelectedItem == null)
			{
				MessageBox.Show("没有选择族", "盈建科提示");
				return;
			}
			int selectedIndex = this.lbRCFamily.SelectedIndex;
			int widthNameIndex = this.m_RColumnMapping[selectedIndex].WidthNameIndex;
			int heightNameIndex = this.m_RColumnMapping[selectedIndex].HeightNameIndex;
			if (widthNameIndex == -1 && heightNameIndex == -1)
			{
				return;
			}
			this.m_RColumnMapping[selectedIndex].WidthNameIndex = heightNameIndex;
			this.m_RColumnMapping[selectedIndex].HeightNameIndex = widthNameIndex;
			if (heightNameIndex != -1)
			{
				this.tbRCWidth.Text = this.m_RColumnMapping[selectedIndex].SizeProperties[heightNameIndex];
			}
			else
			{
				this.tbRCWidth.Text = "";
			}
			if (widthNameIndex != -1)
			{
				this.tbRCHeight.Text = this.m_RColumnMapping[selectedIndex].SizeProperties[widthNameIndex];
				return;
			}
			this.tbRCHeight.Text = "";
		}

		private void lbRCFamily_MouseMove(object sender, MouseEventArgs e)
		{
			if (this.toolTip.GetToolTip(this.lbRCFamily) == this.lbRCFamily.Tag.ToString())
			{
				return;
			}
			this.toolTip.SetToolTip(this.lbRCFamily, this.lbRCFamily.Tag.ToString());
		}

		private void lbCFamily_MouseMove(object sender, MouseEventArgs e)
		{
			if (this.toolTip.GetToolTip(this.lbCCFamily) == this.lbCCFamily.Tag.ToString())
			{
				return;
			}
			this.toolTip.SetToolTip(this.lbCCFamily, this.lbCCFamily.Tag.ToString());
		}

		private void btnSwap_MouseMove_1(object sender, MouseEventArgs e)
		{
			if (this.toolTip.GetToolTip(this.btnRCSwap) == this.btnRCSwap.Tag.ToString())
			{
				return;
			}
			this.toolTip.SetToolTip(this.btnRCSwap, this.btnRCSwap.Tag.ToString());
		}

		private void lbRBFamily_DrawItem(object sender, DrawItemEventArgs e)
		{
			System.Drawing.Color color = e.BackColor;
			if (!this.m_RBeamMapping[e.Index].IsSet)
			{
				color = System.Drawing.Color.Red;
			}
			e.Graphics.FillRectangle(new SolidBrush(color), e.Bounds);
			e.Graphics.DrawString(((ListBox)sender).Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), e.Bounds);
			e.DrawFocusRectangle();
		}

		private void lbRBFamily_MouseMove(object sender, MouseEventArgs e)
		{
			if (this.toolTip.GetToolTip(this.lbRBFamily) == this.lbRBFamily.Tag.ToString())
			{
				return;
			}
			this.toolTip.SetToolTip(this.lbRBFamily, this.lbRBFamily.Tag.ToString());
		}

		private void lbRBFamily_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (this.lbRBFamily.SelectedItem == null)
			{
				return;
			}
			int selectedIndex = this.lbRBFamily.SelectedIndex;
			this.SetCurrentRectBeamProperties(selectedIndex);
		}

		private void btnSetRBWidth_Click(object sender, EventArgs e)
		{
			if (this.lbRBFamily.SelectedItem == null)
			{
				MessageBox.Show("没有选择族", "盈建科提示");
				return;
			}
			if (this.lbRBProperty.SelectedItem == null)
			{
				MessageBox.Show("没有选择尺寸属性", "盈建科提示");
				return;
			}
			int selectedIndex = this.lbRBFamily.SelectedIndex;
			int selectedIndex2 = this.lbRBProperty.SelectedIndex;
			if (this.m_RBeamMapping[selectedIndex].HeightNameIndex == selectedIndex2)
			{
				MessageBox.Show("宽/高数据不能相同", "盈建科提示");
				return;
			}
			this.m_RBeamMapping[selectedIndex].WidthNameIndex = selectedIndex2;
			this.tbRBWidth.Text = this.m_RBeamMapping[selectedIndex].SizeProperties[selectedIndex2];
			this.Refresh();
		}

		private void btnSetRBHeight_Click(object sender, EventArgs e)
		{
			if (this.lbRBFamily.SelectedItem == null)
			{
				MessageBox.Show("没有选择族", "盈建科提示");
				return;
			}
			if (this.lbRBProperty.SelectedItem == null)
			{
				MessageBox.Show("没有选择尺寸属性", "盈建科提示");
				return;
			}
			int selectedIndex = this.lbRBFamily.SelectedIndex;
			int selectedIndex2 = this.lbRBProperty.SelectedIndex;
			if (this.m_RBeamMapping[selectedIndex].WidthNameIndex == selectedIndex2)
			{
				MessageBox.Show("宽/高数据不能相同");
				return;
			}
			this.m_RBeamMapping[selectedIndex].HeightNameIndex = selectedIndex2;
			this.tbRBHeight.Text = this.m_RBeamMapping[selectedIndex].SizeProperties[selectedIndex2];
			this.Refresh();
		}

		private void btnRBSwap_Click(object sender, EventArgs e)
		{
			if (this.lbRBFamily.SelectedItem == null)
			{
				MessageBox.Show("没有选择族", "盈建科提示");
				return;
			}
			int selectedIndex = this.lbRBFamily.SelectedIndex;
			int widthNameIndex = this.m_RBeamMapping[selectedIndex].WidthNameIndex;
			int heightNameIndex = this.m_RBeamMapping[selectedIndex].HeightNameIndex;
			if (widthNameIndex == -1 && heightNameIndex == -1)
			{
				return;
			}
			this.m_RBeamMapping[selectedIndex].WidthNameIndex = heightNameIndex;
			this.m_RBeamMapping[selectedIndex].HeightNameIndex = widthNameIndex;
			if (heightNameIndex != -1)
			{
				this.tbRBWidth.Text = this.m_RBeamMapping[selectedIndex].SizeProperties[heightNameIndex];
			}
			else
			{
				this.tbRBWidth.Text = "";
			}
			if (widthNameIndex != -1)
			{
				this.tbRBHeight.Text = this.m_RBeamMapping[selectedIndex].SizeProperties[widthNameIndex];
				return;
			}
			this.tbRBHeight.Text = "";
		}

		private void btnRBSwap_MouseMove(object sender, MouseEventArgs e)
		{
			if (this.toolTip.GetToolTip(this.btnRBSwap) == this.btnRBSwap.Tag.ToString())
			{
				return;
			}
			this.toolTip.SetToolTip(this.btnRBSwap, this.btnRBSwap.Tag.ToString());
		}

		private List<RectSectionMapping> m_RBeamMapping = new List<RectSectionMapping>();

		private List<RectSectionMapping> m_RColumnMapping = new List<RectSectionMapping>();

		private List<CircleSectionMapping> m_CColumnMapping = new List<CircleSectionMapping>();
	}
}
